<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise的几个关键问题1</title>
  </head>

  <body>
    <script>
      /* 
    1.	如何改变promise的状态?
      (1)resolve(value): 如果当前是pendding就会变为resolved
      (2)reject(reason): 如果当前是pendding就会变为rejected
      (3)抛出异常: 如果当前是pendding就会变为rejected
    
    2.	一个promise指定多个成功/失败回调函数, 都会调用吗?
      当promise改变为对应状态时都会调用
    */

      const p = new Promise((resolve, reject) => {
        // resolve(1) // promise变为resolved成功状态
        // reject(2) // promise变为rejected失败状态
        // throw new Error('出错了') // 抛出异常, promse变为rejected失败状态, reason为 抛出的error
        throw 3 // 抛出异常, promse变为rejected失败状态, reason为 抛出的3
      })

      p.then(
        value => {},
        reason => {
          console.log('reason', reason)
        }
      )
      p.then(
        value => {},
        reason => {
          console.log('reason2', reason)
        }
      )
    </script>
  </body>

</html>